﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QSMonitor
{
    public partial class frmTWM : Form
    {
        DataTable rateDT = null;

        public frmTWM()
        {
            InitializeComponent();
            createDataTable();
            ucBrowser1.NavigateURL("https://fctc.bot.com.tw/botfe/buy2_1.jsp");
            timer1.Start();
        }

        protected void processRate()
        {
            ucBrowser1.NavigateURL("https://fctc.bot.com.tw/botfe/buy2_1.jsp");
            // <table width="540"
            List<HtmlElement> sele = ucBrowser1.GetElementByName("table", "width", new string[] { "540" });
            HtmlElementCollection trs = sele[0].GetElementsByTagName("tr");
            HtmlElementCollection tds = trs[10].GetElementsByTagName("td");
            DataRow row = rateDT.NewRow();
            row[0] = DateTime.Now;
            row[1] = tds[2].InnerText;
            rateDT.Rows.Add(row);
            ucGrid1.SetData(rateDT);
        }

        protected void createDataTable()
        {
            rateDT = new DataTable();
            DataColumn col = new DataColumn();
            col.DataType = typeof(System.DateTime);
            col.Caption = "時間";
            rateDT.Columns.Add(col);

            col = new DataColumn();
            col.DataType = typeof(System.String);
            col.Caption = "Rate";
            rateDT.Columns.Add(col);


        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            processRate();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            processRate();
            timer1.Start();
        }
    }
}
